package smedi.ismedi.web.bff.controller.safetycheck;

import com.smedi.ismedi.safetycheck.dto.request.video.AddLawEnforcementVideoRequest;
import com.smedi.ismedi.safetycheck.dto.request.video.SearchLawEnforcementVideoRequest;
import com.smedi.ismedi.safetycheck.dto.request.video.VideoInfoRequest;
import com.smedi.ismedi.safetycheck.dto.response.PaginationResponse;
import com.smedi.ismedi.safetycheck.dto.response.video.LawEnforcementVideoResponse;
import com.smedi.ismedi.safetycheck.dto.response.video.VideoInfoResponse;
import com.smedi.ismedi.safetycheck.dto.response.video.VoucherResponse;
import com.smedi.ismedi.safetycheck.feign.RemoteLawEnforcementVideoFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = {"执法影像接口"})
@RequestMapping("/webbff/v1/lawEnforcementVideo")
@AllArgsConstructor
public class LawEnforcementVideoController {
    private final RemoteLawEnforcementVideoFeignApi remoteLawEnforcementVideoFeignApi;

    /**
     * 执法影像查询
     *
     * @param searchLawEnforcementVideoRequest
     * @return
     */
    @ApiOperation(value = "执法影像查询", nickname = "执法影像查询")
    @GetMapping(value = "/searchLawEnforcementVideo")
    ResponseData<PaginationResponse<LawEnforcementVideoResponse>> searchLawEnforcementVideo(@Validated @SpringQueryMap SearchLawEnforcementVideoRequest searchLawEnforcementVideoRequest) {
        return remoteLawEnforcementVideoFeignApi.searchLawEnforcementVideo(searchLawEnforcementVideoRequest);

    }

    /**
     * 执法影像新增
     *
     * @param addLawEnforcementVideoRequest
     * @return
     */
    @ApiOperation(value = "执法影像新增", nickname = "执法影像新增")
    @PostMapping(value = "/addLawEnforcementVideo")
    ResponseData<LawEnforcementVideoResponse> addLawEnforcementVideo(@Validated @ApiParam(value = "param", required = true) @RequestBody AddLawEnforcementVideoRequest addLawEnforcementVideoRequest) {
        return remoteLawEnforcementVideoFeignApi.addLawEnforcementVideo(addLawEnforcementVideoRequest);
    }

    /**
     * 删除执法影像
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除执法影像", nickname = "删除执法影像")
    @GetMapping(value = "/deleteLawEnforcementVideo")
    ResponseData<Boolean> deleteLawEnforcementVideo(@RequestParam("id") Long id) throws Exception {
        return remoteLawEnforcementVideoFeignApi.deleteLawEnforcementVideo(id);
    }

    /**
     * 刷新视频上传凭证
     */
    @ApiOperation(value = "刷新视频上传凭证", nickname = "刷新视频上传凭证", response = ResponseData.class)
    @GetMapping(value = "/refreshVoucher")
    ResponseData<VoucherResponse> refreshVoucher(@RequestParam(value = "videoId", required = true) String videoId) throws Exception {
        return remoteLawEnforcementVideoFeignApi.refreshVoucher(videoId);
    }

    /**
     * 获取视频上传地址和凭证
     */
    @ApiOperation(value = "获取视频上传地址和凭证", nickname = "获取视频上传地址和凭证", response = ResponseData.class)
    @PostMapping(value = "/getVoucher")
    ResponseData<VoucherResponse> getVoucher(@RequestBody VideoInfoRequest videoInfoRequest) throws Exception {
        return remoteLawEnforcementVideoFeignApi.getVoucher(videoInfoRequest);
    }


    /**
     * @param id
     */
    @ApiOperation(httpMethod = "GET", value = "下载视频")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "视频id", dataType = "Long"),
    })
    @GetMapping(value = "/exportSafetyCheckBatch")
    ResponseData<List<VideoInfoResponse>> getDownLoadURLs(@RequestParam("id") Long id) throws Exception {
        return remoteLawEnforcementVideoFeignApi.getDownLoadURLs(id);
    }

    /**
     * 校验视频可否播放
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "校验视频可否播放", nickname = "校验视频可否播放")
    @GetMapping(value = "/checkPlayVideo")
    ResponseData<List<VideoInfoResponse>> checkPlayVideo(@RequestParam("id") Long id) {
        return remoteLawEnforcementVideoFeignApi.checkPlayVideo(id);
    }

    @ApiOperation(value = "删除超过1个月的视频", nickname = "删除超过1个月的视频")
    @PostMapping(value = "/deleteUselessVideo")
    void deleteUselessVideo() {
        remoteLawEnforcementVideoFeignApi.deleteUselessVideo();
    }
}
